/*
 * ChannelServer.h
 *
 *  Created on: 2014. 7. 17.
 *      Author: mega
 */

#ifndef GUILDSERVER_CHANNELSERVER_H_
#define GUILDSERVER_CHANNELSERVER_H_


#include <Dispatcher/Static.h>

#include "../idl/Guild.h"


namespace GuildServer {

class ChannelServer : public Dispatcher::Session
{
public:
	ChannelServer();
	virtual ~ChannelServer();

public:
	template <class MSG> void SendMsg(const MSG& msg)
	{
		Dispatcher::ListenHandler<Session, Network::Packet>::SendMsg(this, msg);
	}

	template <class MSG> void SendFail(MSG& msg, int16_t result)
	{
		msg.result = result;
		SendMsg(msg);
	}

	uint32_t	GetChannelKey();

private:
	uint32_t	m_nChannelKey;

};

struct Msg
{
public:
	static void OnLoginGuildMemberSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnLogoutGuildMemberSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnGuildInfoSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnGuildMemberSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnCreateGuildSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnJoinGuildSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnLeaveGuildSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnKickoutGuildMemberSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnSearchGuildSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnGuildBuffGachyaSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnUpdateGuildJoinPasswordSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnUpdateGuildNoticeSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnUpdateGuildNoticeTextSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnApplyGuildPointSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnSendGuildMailCheckSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnUpdateGuildLevelSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnGuildCoolDownSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnGuildListSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnUpdateGuildLoginTimeSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void OnGuildChatSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);

	static void OnReloadResourceSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);

private:
	static int OnRecoverGuild( uint32_t a_user_seq, uint32_t a_guild_seq, RecoverGuildAck& ack );
};

struct InitState : public Dispatcher::Session::State
{
public:
	InitState()
	{
		AddCommand(LoginGuildMemberSyn::MSG_ID, Msg::OnLoginGuildMemberSyn);
		AddCommand(LogoutGuildMemberSyn::MSG_ID, Msg::OnLogoutGuildMemberSyn);
		AddCommand(GuildInfoSyn::MSG_ID, Msg::OnGuildInfoSyn);
		AddCommand(GuildMemberSyn::MSG_ID, Msg::OnGuildMemberSyn);
		AddCommand(CreateGuildSyn::MSG_ID, Msg::OnCreateGuildSyn);
		AddCommand(JoinGuildSyn::MSG_ID, Msg::OnJoinGuildSyn);
		AddCommand(LeaveGuildSyn::MSG_ID, Msg::OnLeaveGuildSyn);
		AddCommand(KickoutGuildMemberSyn::MSG_ID, Msg::OnKickoutGuildMemberSyn);
		AddCommand(SearchGuildSyn::MSG_ID, Msg::OnSearchGuildSyn);
		AddCommand(GuildBuffGachyaSyn::MSG_ID, Msg::OnGuildBuffGachyaSyn);
		AddCommand(UpdateGuildJoinPasswordSyn::MSG_ID, Msg::OnUpdateGuildJoinPasswordSyn);
		AddCommand(UpdateGuildNoticeSyn::MSG_ID, Msg::OnUpdateGuildNoticeSyn);
		AddCommand(UpdateGuildNoticeTextSyn::MSG_ID, Msg::OnUpdateGuildNoticeTextSyn);
		AddCommand(ApplyGuildPointSyn::MSG_ID, Msg::OnApplyGuildPointSyn);
		AddCommand(SendGuildMailCheckSyn::MSG_ID, Msg::OnSendGuildMailCheckSyn);
		AddCommand(UpdateGuildLevelSyn::MSG_ID, Msg::OnUpdateGuildLevelSyn);
		AddCommand(GuildCoolDownSyn::MSG_ID, Msg::OnGuildCoolDownSyn);
		AddCommand(GuildListSyn::MSG_ID, Msg::OnGuildListSyn);
		AddCommand(UpdateGuildLoginTimeSyn::MSG_ID, Msg::OnUpdateGuildLoginTimeSyn);
		AddCommand(GuildChatSyn::MSG_ID, Msg::OnGuildChatSyn);

		AddCommand(ReloadResourceSyn::MSG_ID, Msg::OnReloadResourceSyn);
	}
};

} /*GuildServer*/

#endif //GUILDSERVER_CHANNELSERVER_H_
